package cn.edu.sdjzu.xg.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

public class ControllerHelper {
    /**
     * 获得代表查询条件的List对象
     *
     * @param req_jsonObj 请求body对应的JSONObject对象
     * @return 代表查询条件的List对象
     */
    public static List<Condition> getConditions(JSONObject req_jsonObj) {
        JSONArray conditionList_jsonArray =
                req_jsonObj.getJSONArray("conditionList");
        List<Condition> conditionList = null;
        if (conditionList_jsonArray != null) {
            conditionList = conditionList_jsonArray.toJavaList(Condition.class);
        }
        return conditionList;
    }

    /**
     * 获得代表查询条件的Pagination对象
     *
     * @param req_jsonObj 请求body对应的JSONObject对象*@return代表查询条件的Pagination对象
     */
    public static Pagination getPagination(JSONObject req_jsonObj) {
        JSONObject pagination_jsonObj =
                req_jsonObj.getJSONObject("pagination");
        Pagination pagination = null;
        if (pagination_jsonObj != null) {
            pagination = pagination_jsonObj.toJavaObject(Pagination.class);
        }
        return pagination;
    }
}
